package com.jsss.echarts.entity;

import com.jsss.echarts.annotation.ChineseName;
import lombok.*;

import java.sql.Date;
import java.text.DecimalFormat;
import java.util.Objects;

/**
 * 通用数据
 */
@Data
@NoArgsConstructor
//@ToString
public class GeneralData extends EldData{

    @ChineseName("通用-身高(米)")
    Double HT;

    @ChineseName("通用-体重(千克)")
    Integer WT;

    @ChineseName("通用-身高体重指数(千克/米2)")
    Double BMI;

    //横轴的注解的值是datax
//    @ChineseName("datax")
    Date subDate;


    public GeneralData(Double HT, Integer WT) {
        this.HT = HT;
        this.WT = WT;
        this.BMI= getBMI(HT, WT);
    }


    public GeneralData(Double HT, Integer WT, Date date) {
        super(date);
        this.HT = HT;
        this.WT = WT;
        this.BMI= getBMI(HT, WT);
        this.subDate = date;
    }


    private Double getBMI(Double HT, Integer WT) {
        double value = WT / Math.pow(HT, 2);
        double roundedValue =Math.round(value * 10.0) / 10.0;
        DecimalFormat df = new DecimalFormat("#.0");
        String formattedValue = df.format(roundedValue);
        return Double.parseDouble(formattedValue);
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        GeneralData that = (GeneralData) o;
        return Objects.equals(HT, that.HT) && Objects.equals(WT, that.WT) && Objects.equals(BMI, that.BMI);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), HT, WT, BMI);
    }

    @Override
    public String toString() {
        return "GeneralData{" +
                "HT=" + HT +
                ", WT=" + WT +
                ", BMI=" + BMI +
                ", date=" + date +
                '}';
    }
}
